home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / workbench / libs / dummylib.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  6KB  |  249 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dummylib.c,v 1.8 1997/01/27 00:22:41 ldp Exp $
  4.     $Log: dummylib.c,v $
  5.     Revision 1.8  1997/01/27 00:22:41  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.7  1996/10/24 15:51:27  aros
  9.     Use the official AROS macros over the __AROS versions.
  10.  
  11.     Revision 1.6  1996/10/23 14:05:18  aros
  12.     Missing include
  13.  
  14.     Revision 1.5  1996/09/13 17:57:09  digulla
  15.     Use IPTR
  16.  
  17.     Revision 1.4  1996/09/12 14:52:04  digulla
  18.     Use correct way to access external names (was missing)
  19.  
  20.     Revision 1.3  1996/08/13 15:35:11  digulla
  21.     Replaced AROS_LA by AROS_LHA
  22.  
  23.     Revision 1.2  1996/08/01 17:41:28  digulla
  24.     Added standard header for all files
  25.  
  26.     Desc:
  27.     Lang:
  28. */
  29. #include <exec/types.h>
  30. #include <exec/resident.h>
  31. #include <proto/exec.h>
  32. #include <aros/libcall.h>
  33. #ifdef __GNUC__
  34. #   include "dummylib_gcc.h"
  35. #endif
  36. #include "initstruct.h"
  37. #include <stddef.h>
  38.  
  39. struct inittable;
  40. extern const char name[];
  41. extern const char version[];
  42. extern const APTR inittabl[4];
  43. extern void *const functable[];
  44. extern const struct inittable datatable;
  45. extern struct dummybase *AROS_SLIB_ENTRY(init,dummy)();
  46. extern struct dummybase *AROS_SLIB_ENTRY(open,dummy)();
  47. extern BPTR AROS_SLIB_ENTRY(close,dummy)();
  48. extern BPTR AROS_SLIB_ENTRY(expunge,dummy)();
  49. extern int AROS_SLIB_ENTRY(null,dummy)();
  50. extern ULONG AROS_SLIB_ENTRY(add,dummy)();
  51. extern ULONG AROS_SLIB_ENTRY(asl,dummy)();
  52. extern const char end;
  53.  
  54. int entry(void)
  55. {
  56.     /* If the library was executed by accident return error code. */
  57.     return -1;
  58. }
  59.  
  60. const struct Resident resident=
  61. {
  62.     RTC_MATCHWORD,
  63.     (struct Resident *)&resident,
  64.     (APTR)&end,
  65.     RTF_AUTOINIT,
  66.     1,
  67.     NT_LIBRARY,
  68.     0,
  69.     (char *)name,
  70.     (char *)&version[6],
  71.     (ULONG *)inittabl
  72. };
  73.  
  74. const char name[]="dummy.library";
  75.  
  76. const char version[]="$VER: dummy 1.0 (28.3.96)\n\015";
  77.  
  78. const APTR inittabl[4]=
  79. {
  80.     (APTR)sizeof(struct dummybase),
  81.     (APTR)functable,
  82.     (APTR)&datatable,
  83.     &AROS_SLIB_ENTRY(init,dummy)
  84. };
  85.  
  86. void *const functable[]=
  87. {
  88.     &AROS_SLIB_ENTRY(open,dummy),
  89.     &AROS_SLIB_ENTRY(close,dummy),
  90.     &AROS_SLIB_ENTRY(expunge,dummy),
  91.     &AROS_SLIB_ENTRY(null,dummy),
  92.     &AROS_SLIB_ENTRY(add,dummy),
  93.     &AROS_SLIB_ENTRY(asl,dummy),
  94.     (void *)-1
  95. };
  96.  
  97. struct inittable
  98. {
  99.     S_CPYO(1,1,B);
  100.     S_CPYO(2,1,L);
  101.     S_CPYO(3,1,B);
  102.     S_CPYO(4,1,W);
  103.     S_CPYO(5,1,W);
  104.     S_CPYO(6,1,L);
  105.     S_END (end);
  106. };
  107.  
  108. #define O(n) offsetof(struct dummybase,n)
  109.  
  110. const struct inittable datatable=
  111. {
  112.     { { I_CPYO(1,B,O(library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  113.     { { I_CPYO(1,L,O(library.lib_Node.ln_Name)), { (IPTR)name } } },
  114.     { { I_CPYO(1,B,O(library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  115.     { { I_CPYO(1,W,O(library.lib_Version     )), { 1 } } },
  116.     { { I_CPYO(1,W,O(library.lib_Revision    )), { 0 } } },
  117.     { { I_CPYO(1,L,O(library.lib_IdString    )), { (IPTR)&version[6] } } },
  118.     I_END ()
  119. };
  120.  
  121. #undef O
  122.  
  123. AROS_LH2(struct dummybase *, init,
  124.  AROS_LHA(struct dummybase *, dummybase, D0),
  125.  AROS_LHA(BPTR,               segList,   A0),
  126.        struct ExecBase *, SysBase, 0, dummy)
  127. {
  128.     AROS_LIBFUNC_INIT
  129.     /* This function is single-threaded by exec by calling Forbid. */
  130.  
  131.     /* Store arguments */
  132.     dummybase->sysbase=SysBase;
  133.     dummybase->seglist=segList;
  134.  
  135.     /* You would return NULL here if the init failed. */
  136.     return dummybase;
  137.     AROS_LIBFUNC_EXIT
  138. }
  139.  
  140. /* Use This from now on */
  141. #ifdef SysBase
  142. #undef SysBase
  143. #endif
  144. #define SysBase dummybase->sysbase
  145.  
  146. AROS_LH1(struct dummybase *, open,
  147.  AROS_LHA(ULONG, version, D0),
  148.        struct dummybase *, dummybase, 1, dummy)
  149. {
  150.     AROS_LIBFUNC_INIT
  151.     /*
  152.     This function is single-threaded by exec by calling Forbid.
  153.     If you break the Forbid() another task may enter this function
  154.     at the same time. Take care.
  155.     */
  156.  
  157.     /* Keep compiler happy */
  158.     version=0;
  159.  
  160.     /* I have one more opener. */
  161.     dummybase->library.lib_OpenCnt++;
  162.     dummybase->library.lib_Flags&=~LIBF_DELEXP;
  163.  
  164.     /* You would return NULL if the open failed. */
  165.     return dummybase;
  166.     AROS_LIBFUNC_EXIT
  167. }
  168.  
  169. AROS_LH0(BPTR, close, struct dummybase *, dummybase, 2, dummy)
  170. {
  171.     AROS_LIBFUNC_INIT
  172.     /*
  173.     This function is single-threaded by exec by calling Forbid.
  174.     If you break the Forbid() another task may enter this function
  175.     at the same time. Take care.
  176.     */
  177.  
  178.     /* I have one fewer opener. */
  179.     if(!--dummybase->library.lib_OpenCnt)
  180.     {
  181.     /* Delayed expunge pending? */
  182.     if(dummybase->library.lib_Flags&LIBF_DELEXP)
  183.         /* Then expunge the library */
  184.         return expunge();
  185.     }
  186.     return 0;
  187.     AROS_LIBFUNC_EXIT
  188. }
  189.  
  190. AROS_LH0(BPTR, expunge, struct dummybase *, dummybase, 3, dummy)
  191. {
  192.     AROS_LIBFUNC_INIT
  193.  
  194.     BPTR ret;
  195.     /*
  196.     This function is single-threaded by exec by calling Forbid.
  197.     Never break the Forbid() or strange things might happen.
  198.     */
  199.  
  200.     /* Test for openers. */
  201.     if(dummybase->library.lib_OpenCnt)
  202.     {
  203.     /* Set the delayed expunge flag and return. */
  204.     dummybase->library.lib_Flags|=LIBF_DELEXP;
  205.     return 0;
  206.     }
  207.  
  208.     /* Get rid of the library. Remove it from the list. */
  209.     Remove(&dummybase->library.lib_Node);
  210.  
  211.     /* Get returncode here - FreeMem() will destroy the field. */
  212.     ret=dummybase->seglist;
  213.  
  214.     /* Free the memory. */
  215.     FreeMem((char *)dummybase-dummybase->library.lib_NegSize,
  216.         dummybase->library.lib_NegSize+dummybase->library.lib_PosSize);
  217.  
  218.     return ret;
  219.     AROS_LIBFUNC_EXIT
  220. }
  221. AROS_LH0I(int, null, struct dummybase *, dummybase, 4, dummy)
  222. {
  223.     AROS_LIBFUNC_INIT
  224.     return 0;
  225.     AROS_LIBFUNC_EXIT
  226. }
  227.  
  228. AROS_LH2I(ULONG, add,
  229.     AROS_LHA(ULONG,a,D0),
  230.     AROS_LHA(ULONG,b,D1),
  231.     struct dummybase *,dummybase,5,dummy)
  232. {
  233.     AROS_LIBFUNC_INIT
  234.     return a+b;
  235.     AROS_LIBFUNC_EXIT
  236. }
  237.  
  238. AROS_LH2I(ULONG, asl,
  239.     AROS_LHA(ULONG,a,D0),
  240.     AROS_LHA(ULONG,b,D1),
  241.     struct dummybase *,dummybase,6,dummy)
  242. {
  243.     AROS_LIBFUNC_INIT
  244.     return a<<b;
  245.     AROS_LIBFUNC_EXIT
  246. }
  247.  
  248. const char end=0;
  249.